package com.base;

/**
 * Created by yijy on 2018/3/5.
 */
public class EXchangeInt {

        /**
         * 不用第三个变量，交换两个int数
         */
        public static void exchange(int a,int b){
            System.out.println("a=" + a +",b=" + b);
            if(a*b>0){
                //同号
                b = a-b;
                a = a-b;
                b = a + b;
            } else {
                //一正一负
                b= a+b;
                a= b-a;
                b=b-a;
            }
            System.out.println("a=" + a +",b=" + b);
        }

        public static void main(String[] args){
            int a = 2;
            int b = -9;
            exchange(a,b);
            exchangeString("123","abc");
        }

    public static void exchangeString(String a,String b){
        System.out.println("a="+a+",b="+b);
        a = a+b;
        b = a.substring(0,a.length()-b.length());
        a = a.substring(b.length());
        System.out.println("a="+a+",b="+b);
    }


}
